<?php
namespace Home\Controller;
use Common\Common\Classes\Message;
use Home\Model\ClassService;
use Home\Model\CourseService;
use Think\Controller;
class TeaCourseController extends HomeController{
    public function course(){
        $cou_sql = new CourseService();
        $pageInfo = $cou_sql->getPageInfo();            //分页处理
        $cou_field = array("cou_id","cou_name","cou_code","is_available");      //需要获取的字段
        $course = $cou_sql->getTenCoursesInfo($pageInfo["np"],$cou_field);
        $cla_sql = new ClassService();
        $filedClass = $cla_sql->getAllClasses(1,1);
        if(count($filedClass)>0){
            $has_filed = 1;
        }
        else{
            $has_filed = 0;
        }
        $this->assign("has_filed",$has_filed);
        $this->assign("pageinfo", $pageInfo);
        $this->assign("courses", $course);
        $this->display();
    }
    //---------------------------------创建课程的方法---------------------------------
    public function addCourse(){
        if(IS_AJAX){
            $cou_sql = new CourseService();
            $data = $cou_sql->addCourse();
            $this->ajaxReturn($data);
        }
    }
    //---------------------------------检测能否删除课程---------------------------------
    public function deleteCourse(){
        if(IS_AJAX) {
            $cou_sql = new CourseService();
            $data = $cou_sql->checkPower();        //检测权限
            if($data->status==1) {             //如果返回1表示有权限
                $data = $cou_sql->checkDelete();        //作具体操作,并且修改data为从操作后的data
            }
            $this->ajaxReturn($data);       //返回数据
        }
    }
    //---------------------------------确认删除---------------------------------
    public function deleteCourseConfirm() {
        if(IS_AJAX){
            $cou_sql = new CourseService();
            $data = $cou_sql->checkPower();
            if($data->status == 1) {
                $data = $cou_sql->deleteCourse();
            }
            $this->ajaxReturn($data);
        }
    }
    //---------------------------------修改课程基本信息的方法---------------------------------
    public function updateCourse(){
        if(IS_AJAX){
            $cou_sql = new CourseService();
            $data = $cou_sql->checkPower();
            if($data->status == 1) {
                $data = $cou_sql->updateCourse();
            }
            $this->ajaxReturn($data);
        }
    }
}